{% extends "sentry/bases/account.html" %}

{% load crispy_forms_tags %}
{% load i18n %}
{% load sentry_auth %}
{% load sentry_helpers %}

{% block title %}{% trans "Subscriptions" %} | {{ block.super }}{% endblock %}

{% block main %}
    {% if not email.is_verified %}
      <div class="alert alert-warning alert-block">
        {% trans "Your email address has not been verified. " %}
        <form action="{% url 'sentry-account-confirm-email-send' %}" method="post" class="email-alert-button">
          {% csrf_token %}
          <input type="hidden" name="email" value="{{ email.email }}">
          <button type="submit" name="primary-email" class="btn-link">{% trans "Resend Verification Email." %}</button>
        </form>
      </div>
    {% endif %}

    <legend class="m-t-0">Subscriptions</legend>

    <p>
      Sentry is committed to respecting your inbox. Our goal is to provide useful
      content and resources that make fixing errors less painful. Enjoyable even.
    </p>

    <p>
      As part of our compliance with the EU’s General Data Protection Regulation
      (GDPR), starting on 25 May 2018, we’ll only email you according to the
      marketing categories to which you’ve explicitly opted-in.
    </p>

    <table class="table">
      <tbody>
    {% for subscription in subscriptions.subscriptions %}
        <tr>
          <td>
            <h5>{{ subscription.list_name }}</h5>
            {% if subscription.list_description %}
            <p class="help-block">
              {{ subscription.list_description }}
            </p>
            {% endif %}
          </td>
          <td class="align-right">
              <div data-list-id="{{ subscription.list_id }}" class="switch switch-lg{% if subscription.subscribed %} switch-on{% endif %}" role="checkbox">
                  <span class="switch-toggle"></span>
              </div>
              <div>
            {% if subscription.subscribed %}
            <p class="help-block">
              <small>
                {% firstof subscription.email email.email %} on {{subscription.subscribed_date|date:'SHORT_DATE_FORMAT' }}
              </small>
            </p>
            {% endif %}
            </div>
          </td>
        </tr>
    {% endfor %}
      </tbody>
    </table>

    <p>
      We’re applying GDPR consent and privacy policies to all Sentry contacts,
      regardless of location. You’ll be able to manage your subscriptions here
      and from an Unsubscribe link in the footer of all marketing emails.
    </p>

    <p>
      Please contact {{ "learn@sentry.io"|urlize }} with any questions or suggestions.
    </p>

    <script>
    $('div.switch').click(function(){
        var $e = $(this);
        $e.toggleClass('switch-on');
        $.post('{% url 'sentry-account-settings-subscriptions' %}', {
            'subscribed': $e.hasClass('switch-on') ? '1' : '0',
            'listId': $e.data('list-id')
        });
    });
    </script>
{% endblock %}
